package router

import (
	"Data-API-MCP/backend/configs"
	"Data-API-MCP/backend/internal/base/middleware"
	"Data-API-MCP/backend/internal/interfaces/http/handler"

	"github.com/gin-gonic/gin"
)

// SetupRouter 设置路由
// @param config *configs.Config 配置
// @param handlers *Handlers 处理器
// @return *gin.Engine 路由
func SetupRouter(config *configs.Config, handlers *Handlers) *gin.Engine {
	r := gin.New()

	// 使用中间件
	r.Use(middleware.Logger())
	r.Use(middleware.CORS(config))
	r.Use(gin.Recovery())

	// 创建API路由组
	apiGroup := r.Group("/api/v1")
	{
		// 注册用户相关路由
		RegisterUserRoutes(apiGroup, handlers.UserHandler)

		// 注册数据库连接相关路由
		RegisterDBRoutes(apiGroup, handlers.DBHandler)

		// 注册API管理相关路由
		RegisterAPIRoutes(apiGroup, handlers.APIHandler)

		// 注册统计相关路由
		RegisterStatisticsRoutes(apiGroup, handlers.StatisticsHandler)

		// 注册MCP服务相关路由
		RegisterMCPRoutes(apiGroup, handlers.MCPHandler)
	}

	return r
}

// Handlers 处理器集合
type Handlers struct {
	UserHandler       *handler.UserHandler
	DBHandler         *handler.DBHandler
	APIHandler        *handler.APIHandler
	StatisticsHandler *handler.StatisticsHandler
	MCPHandler        *handler.MCPServiceHandler
}
